Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

350
Visualizações
How to change the visibility for the "logger" service on Symfony?

I have recently upgraded from Symfony 3.4 to 4.4

The codebase is really large and there are a lot of references to container->get('logger') from all over the place.

I have been trying to make this service public, but not having any luck with any examples I can find. Error:

The "logger" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

In my service.yml I have tried this with no luck:

Psr\Log\LoggerInterface:
 public: true

Psr\Log\LoggerInterface:
 alias: 'logger'
 public: true

Psr\Log\LoggerInterface:
 alias: 'monolog.logger'
 public: true

How can I make the logger service public?

NOTE: in the upgrade from 3.4->4.4 we did not update the codebase to use Symfony Flex

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You would do this with a Compiler Pass. (Docs are for 4.4, since that's the version you are using, current docs are here).

Change your application Kernel so it implements CompilerPassInterface, and on the process() method you can manipulate the service container directly:

// src/Kernel.php
namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel implements CompilerPassInterface
{
    use MicroKernelTrait;

    // ...

    public function process(ContainerBuilder $container): void
    {
        $container->getDefinition('monolog.logger')->setPublic(true);
    }
}

In any case, if I were you I'd investigate using something like Rector to automatically update your code. It even includes a rule for this specific use-case, converting the (ab)use of injected container and public services into proper dependency injection.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda